<?php 
	session_start();
	if (!isset($_SESSION['username'])) {
		echo "<script language='javascript'>";
		echo "alert('You have no permission to read this page!');";
		echo "history.back();";
		echo "</script>";
		header("location:../login.php");
	}elseif ($_GET["id"]==Null) {
		header("location:index.php?id=".$_SESSION['uid']);
	}else {
		$id = $_GET["id"];
		$whoami = $_SESSION['uid'];
		require('../host_config.php');
		require('../Controller/profile_controller.php');
		require('../Controller/message_controller.php');
		require('../Controller/makefriend_controller.php');
		require_once('../Model/MySQL.php');
		
		$mysql = new MySQL();
		$link = $mysql->connect($mysql_host, $mysql_user, $mysql_password, $mysql_db);
		$con_profile = new Profile_Controller();
		$profile_data = $con_profile->showProfile($id);
		$control = new Message_Controller();
		$mf_control = new MakeFriend_Controller();
?>
<html>

<head>
	<link rel="stylesheet" href="../CSS/autocomplete/autocomplete.css" type="text/css" media="screen">
	<script src="../CSS/autocomplete/dimensions.js" type="text/javascript"></script>
    <script src="../CSS/autocomplete/autocomplete.js" type="text/javascript"></script>
	<script language="javascript">
		function show(did){
			var xx=document.getElementById(did).style.display;
			if(xx==""){
				document.getElementById(did).style.display="none";
			}else{
				document.getElementById(did).style.display="";
			}
		}
	</script>
	<script type="text/javascript">
    	$(function(){
        	setAutoComplete("searchPeople", "results", "autocomplete.php?part=");
        });
    </script>
	<meta http-equiv="Content-Type" content="width=device-width; text-html; charset=utf-8" />
	<script type="text/javascript" src="../CSS/bootstrap/js/jquery.js"></script>
    <script type="text/javascript" src="../CSS/bootstrap/js/bootstrap.min.js"></script>	
	<link href="../CSS/bootstrap/css/bootstrap.css" rel="stylesheet" />
	    <link rel="stylesheet" href="../CSS/bootstrap/css/font-awesome.css">	    
	<title>FaceTech</title>	        
	<style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="../CSS/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
	<style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
      .sidebar-nav {
        padding: 9px 0;
      }
      .media, .media-body {
    		overflow:hidden;
    		*overflow:visible;
    		zoom:1;
    	}
    	.media {
    		margin-bottom: 10px;
    	}
    	.media .media {
    		margin-top: 20px;
    	}
    	.media .pull-left {
    		margin-right: 10px;
    	}
    	.media .pull-right {
    		margin-left: 10px;
    	}
    	.media .media-object {
    		display: block;
    	}
    	/* Media list */
    	.medias {
    		margin-top: 20px;
    		margin-left: 0;
    		list-style-type: none;
    	}
    	.medias .media {
    		padding-bottom: 10px;
    		border-bottom: 1px solid rgba(0,0,0,.07);
    	}
    	.medias > .media:last-child {
    		margin: 0;
    		border-bottom: none;
    	}
    	.medias > .media .media {
    		margin-bottom: 0;
    		padding-bottom: 0;
    		border-bottom: none;
    	} 
    	/* Media box */
    	.media-box {
    		margin-bottom: 10px;
    		padding: 10px;
    		background-color: #fff;
    		border: 1px solid rgba(0,0,0,.09);
    		-webkit-border-radius: 4px;
    		-moz-border-radius: 4px;
    		border-radius: 4px;
    		-webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    		-moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    		box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    	}
    	@media (max-width: 480px) {
    	    .media .pull-left,
    	    .media .pull-right  {
    	    	float: none;
    	    	display: block;
    	    	margin-bottom: 10px;
    	    }
    	    .media .pull-left {
    	        margin-right: 0;    
    	    }
    	    .media .pull-right {
    	        margin-left: 0;    
    	    }
    	}
    </style>
    <link href="../CSS/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
	<link href="../CSS/bootstrap/css/bbootstrap.min.css" rel="stylesheet" media="screen">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->    
</head>

<body>	
	<div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="index.php?id=<?php echo $whoami; ?>">FaceTech</a>
          <div class="nav-collapse collapse">
            <ul class="nav">
              <li class="active"><a href="index.php?id=<?php echo $whoami; ?>"><i class="icon-home icon-white" style="margin-top: 3px"></i>Home</a></li>
              <li class="active"><a href="logout.php"><i class="icon-off icon-white" style="margin-top: 3px"></i>Logout</a></li>
              <li class="active"><a href="friends/requests.php"><i class="icon-user icon-white" style="margin-top: 3px"></i>好友邀請確認</a></li>             		
            </ul>
			<form class="navbar-search search-query" method="post" name="navSearch" action="search/search.php" >
				<input name="searchPeople" type="navbar-text" class="input-medium search-query span2" placeholder="Search for people">
				<input type="submit" class="btn btn-inverse btn-small" style="margin-top: 1px;" name=searchbtn value="搜尋"/>					
				<?php 
					if($_POST[searchbtn] )	{
						header("location:../views/search/search.php");
					}	
				?>								
			</form>             
            <p class="navbar-text pull-right">
              Logged in as <a href="index.php?id=<?php echo $whoami; ?>" class="navbar-link">
				<?php
					$row_showname = $control->showName($whoami);
					echo $row_showname[0];
				?>
				</a>
            </p>            
          </div><!--/.nav-collapse -->
        </div> 
      </div>
    </div>
    
	<div class="container">
		<div class="row-fluid">
	        <div class="span3">
			  <div class="well sidebar-nav">
	            <ul class="nav nav-list">
	              <li class="nav-header">About Me</li>
	              <div class="row-fluid">
	              		<?php $row_showname = $control->showName($id)?>
                        <a class="pull-left" href=""><img class="media-object" src=../<?php echo $row_showname[2]; ?> height="64" width="64"/></a>
	              		<div class="span6">
	              			<li>Name：<?php echo $row_showname[1]; ?></li>
	              			<li>Birthday：</li>
	              			<li><?php echo $row_showname[3]; ?></li>
		              	</div>
		          <?php
					$sql = "SELECT owner_id, friend_id FROM `friendlist` where owner_id = '$whoami' and friend_id = '$id'";
					$row = mysql_query($sql, $link);
					$var_temp = null;
					while($rows=mysql_fetch_row($row)){
						$var_temp=$rows[1];
					}
		          	if($whoami==$id) {
		          	}elseif($var_temp==$id){
		          	}else{
		          ?>
		          		<!-- addFriend -->
		              	<div class="pull-right">
		              		<a href="#myModal" role="button" class="btn" data-toggle="modal">Add Friend</a>
							<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
							  <div class="modal-header">
							    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
							    <h3 id="myModalLabel">Add Friend?</h3>
							  </div>
							  <div class="modal-body">
								<form class="navbar-form pull-left" action="./group_add.php" method="post" id="addfriendForm">
								  	<input type="hidden" name="senttoid" value=" <?php echo $id; ?> " />
								  	Type a GroupName：<input type="text" class="span7" name="groupName"><br/>
								  	Or Select a Group ： 
								  	<select name="selectGroup">
								  		<?php 
								  			$mf_control->showGroup($whoami);
								  		?>
									</select>									
								 </form>
							   </div>
							   <div class="modal-footer">
							     <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
							     <button class="btn btn-primary" form="addfriendForm">Add</button>
							   </div>
							</div>										              		
		              	</div>
		              	<!-- addFriend End -->
					<?php
		          	  }
					?>		          	              		       	              	       		              	
	              </div>
	            </ul>
	          </div><!--/.well -->	          
	          <div class="well sidebar-nav">
	            <ul class="nav nav-list">
	              <li class="nav-header">Sidebar</li>
	              	<li class="divider"></li>
		            <li><a href="profile.php?id=<?php echo $id; ?>">Profile</a></li>
		            <li><a href="index.php?id=<?php echo $id; ?>">Wall</a></li>
		           	<li class="divider"></li>	
					<?php 
					if($whoami!=$id) {
		          	}else{
		           ?>
					<div class="pull-right">
					<!-- ###### Add Group ###### -->
						<a class="btn btn-small" data-toggle="modal" href="javascript:var value = $('#grpName').val();if(value!=''){window.location='../Controller/makefriend_controller.php?action=addGrp&id=<?php echo $whoami; ?>&grpname=' + value;}" onClick=""><i class="icon-plus" style="margin-top: 7px"></i></a>
					<!-- ###### Delete Group ###### -->
						<a class="btn btn-small" data-toggle="modal" href="javascript:var value = $('#grpName').val();if(value!=''){if(confirm('Are you sure?')){window.location='../Controller/makefriend_controller.php?action=delGrp&id=<?php echo $whoami; ?>&grpname=' + value;}}" onClick=""><i class="icon-trash" style="margin-top: 7px"></i></a>
					</div>           
		           	<li><input id="grpName" type="text" class="span2 search-query" style="width:60%" placeholder="Group Name"></li>
		           	<li class="divider"></li>		              		              
					<?php }?>												              								                         
		            <!-- Friend List Start -->
		              <li class="dropdown open">
		              	<a class="dropdown-toggle" data-toggle="dropdown" onclick="show('dt1')">Friends List&nbsp&nbsp<i class="icon-arrow-down" style="margin-top: 3px"></i></a>
		              		<dt id="dt1" style="display:">		              			              		
								<?php
			              			$mf_control->showList($whoami,$id);
			              		?>
		              		</dt>
	              </li>
	              	<!-- Friend List End -->
	            </ul>
	          </div><!--/.well -->
	        </div><!--/span-->
	        <div class="span9"> <!-- 寬度  -->
		      	<div class="row-fluid">
			      	<div class="span9" id="main">
				      	<div style="margin-bottom: 18px;">
				      		<form class="well">
				      			<h3>姓名 : </h3>
				      				<p class="text-warning"><?php echo $profile_data[1];?> </p>		   						
		    					<h3>生日 : </h3>
		    						<p class="text-warning"><?php echo $profile_data[2];?> </p>
								<h3>電話 : </h3>
									<p class="text-warning"><?php echo $profile_data[3];?> </p>
								<?php 
									if($whoami == $id){	
								?>
		   							<input type=button class="btn btn-mini btn-primary" onClick="location.href='profile_edit.php?id=<?php echo $whoami; ?>'" value='編輯'>
		   						<?php 
									}else{
								
									}
		   						?>
		   					</form>	
						</div>
						<div class="media-box">
							<div class="media">
							</div>
						</div>
			      	</div>
		      	</div>
		      	<div style="margin-top: 18px;">
			      <footer>
			        <p>FaceTech &copy; Company 2012</p>
			      </footer> 		
				</div>			      	           
			</div>    
		</div><!--/span-->
      </div><!--/row-->      
	</div>

	
</body>

</html>
<?php 
	}
?>